﻿/// <reference path="../Jquery/jquery-1.4.4-vsdoc.js" />
/// <reference path="../Jquery/jquery-ui-1.8.17.custom.min.js" />
/// <reference path="../BusyIndicator.js" />


var EasySite = function () {

}

EasySite.ajaxPostBusy = function (url, data, successCallBack, busyContent) {
    $.ajax({
        type: "post",
        url: url,
        data: data,
        beforeSend: function (request) {
            var op = new BusyOptions(true);
            if (busyContent == undefined) {
                busyContent = "Loading...";
            }
            op.busyContent = busyContent;
            op.delay = 100;
            op.modal = true;
            op.showCancel = true;
            $.busy(op);
        },
        success: function (result) {
            $.busy(false);
            successCallBack(result);
        },
        error: function (err) {
            $.busy(false);
            if (err.status != 0) {
                alert("Error happened!");
            }
        }
    });
}

EasySite.InitActionResultDialog = function () {
    var wrap = $("<div class='action-message'></div>");
    wrap.appendTo($("body"));
    wrap.dialog({
        autoOpen:false,
        closeText:"hide",
        title:"Message"

    });
}

EasySite.ShowActionResultDialog = function (message, items) {
    var wrap = $(".action-message");
    wrap.empty();
    wrap.append("<div class='action-message'>" + message + "</div>");
    var itemsWrap = $("<div class='action-items'></div>");
    itemsWrap.appendTo(wrap);
    for (var i = 0; i < items.length; i++) {
        var command = $("<div class='command'>" + items[i].Text + "</div>");
        command.appendTo(itemsWrap);
        command.click(function () {
            items[i].Command();//todo: fix bug
        });
    }
    wrap.dialog("open");
}